package com.wuzuqing.android.eightdiagrams

import android.annotation.SuppressLint
import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.view.View
import android.view.inputmethod.InputMethodManager
import android.widget.TextView
import com.wuzuqing.android.eightdiagrams.utils.EightDagramsManager
import com.wuzuqing.android.eightdiagrams.utils.LunarUtil

class ResultActivity : BaseActivity() {

    companion object{
        fun launch(context:Activity){
            val imm = context.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
            imm.hideSoftInputFromWindow(context .window.decorView.windowToken, 0)
            context.startActivity(Intent(context,ResultActivity::class.java))
//            context.finish()
        }
    }
    lateinit var result: TextView
    lateinit var ganZhi: TextView
    lateinit var eigContainer: View
    private var lists: ArrayList<EightDagramsView> = ArrayList()
    @SuppressLint("MissingInflatedId")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_result)

        result = findViewById(R.id.result)
        eigContainer = findViewById(R.id.eightDagramsContainer)
        ganZhi = findViewById(R.id.ganzhi)
        ganZhi.text = LunarUtil.getInstance().resetNow().toString()
        lists.add(findViewById(R.id.eightDagramsView1))
        lists.add(findViewById(R.id.eightDagramsView2))
        lists.add(findViewById(R.id.eightDagramsView3))
        lists.add(findViewById(R.id.eightDagramsView4))
        lists.add(findViewById(R.id.eightDagramsView5))
        val manager = EightDagramsManager.getInstance()

        val models = manager.dagramsInfoModels
        eigContainer.visibility = View.VISIBLE
        lists.forEachIndexed { index, eightDagramsView ->
            eightDagramsView.setValue(models[index])
        }
        result.text = manager.result
    }
}
